package org.hongqi.common.senpec.sys.role;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.RequiredArgsConstructor;
import org.hongqi.common.senpec.base.mybatisplus.IBaseController;
import org.hongqi.common.senpec.base.sevlet.Result;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;

@RestController
@RequestMapping("/sys/roles")
@RequiredArgsConstructor
public class RoleController implements IBaseController<Role> {

    private final RoleService roleService;

    @Override
    @PostMapping
    public Result<Role> save(Role entity) {
        return roleService.mySave(entity);
    }

    @Override
    @DeleteMapping("/{id}")
    public Result<?> removeById(@PathVariable("id") Long id) {
        return roleService.myRemoveById(id);
    }

    @Override
    @PutMapping
    public Result<Role> updateById(Role entity) {
        return roleService.myUpdateById(entity);
    }

    @Override
    @GetMapping("/{id}")
    public Result<Role> getById(@PathVariable(name = "id") Long id) {
        return roleService.myGetById(id);
    }

    @Override
    @PostMapping("/listObjsWithPage")
    public Result<IPage<Role>> listObjsWithPage(Role entity) {
        return roleService.myListObjsWithPage(entity);
    }

    @Override
    @PostMapping("/listObjsWithoutPage")
    public Result<Collection<Role>> listObjsWithoutPage(Role entity) {
        return roleService.myListObjsWithoutPage(entity);
    }

    @GetMapping("/user/{userId}")
    public Result<Collection<Role>> listObjsByUserId(@PathVariable(name = "userId") Long userId) {
        return roleService.myListObjsByUserId(userId);
    }

    @PutMapping("/user/{userId}/role/{roleId}")
    public Result<Collection<Role>> updateRoleIdByUserId(@PathVariable(name = "roleId") Long roleId, @PathVariable(name = "userId") Long userId) {
        return roleService.myUpdateRoleIdByUserId(roleId, userId);
    }

}
